<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<spring:url value="/images/glyphicons_150_edit.png" var="edit"></spring:url>

<script src="${jsUrl}" type="text/javascript"></script>
<script>

function cambiaPagDati(page){
	
	document.getElementById("pagina").value=page;
	document.getElementById("ricercaOpportunitaForm").submit();
}

function resetAndSubmitForm(){
	document.getElementById("pagina").value="1";
	document.getElementById("ricercaOpportunitaForm").submit();
}

</script>
<div class="unit-row">
		<nav class="nav-tabs" style="width:1000px">
			<ul>
				<li><span>Ricerca Opportunita</span></li>
				<li><a href="${flowExecutionUrl}&_eventId=nuova-opportunita">Nuova Opportunita</a></li>
				<li><a href="<c:url value="j_spring_security_logout" />">Logout</a></li>				
			</ul>
		</nav>
		<br />
		<div class="unit-100 unit-centered" style="width:800px">
			<h3 class="head-toc head-toc-start">Ricerca opportunita</h3>
			<form:form id="ricercaOpportunitaForm" cssClass="forms forms-columnar"
				action="${flowExecutionUrl}" method="POST" commandName="ricercaOpportunitaForm" >
				<form:hidden path="searched"/>
				
				<fieldset title="Ricerca Opportunita">
					<p class="forms-inline">
						<form:label path="codice" cssErrorClass="error">Codice da ricercare<em class="req">*</em></form:label>
						<form:select path="codice" cssClass="width-30" maxlength="50"
							cssErrorClass="input-error width-30">
							<form:option value="ALL">Tutte</form:option>
							<form:option value="C">C</form:option>
							<form:option value="T">T</form:option>
							<form:option value="S">S</form:option>
							<form:option value="B">B</form:option>
						</form:select>
						<form:errors path="codice" cssClass="error"></form:errors>
					</p>
					<p class="forms-inline">
						<form:label path="progressivo" cssErrorClass="error">Progressivo</form:label>
						<form:input path="progressivo" cssClass="width-60" maxlength="50"
							cssErrorClass="input-error width-60" />
						<form:errors path="progressivo" cssClass="error"></form:errors>
					</p>
					
					<p class="forms-inline">
						<fmt:formatDate value="${dataDa}" pattern="dd/MM/yyyy" var="dtDa"/>
						<form:label path="dataDa" cssErrorClass="error">Da quando? (GG/MM/AAAA) <em class="req">*</em></form:label>
						<form:input path="dataDa" value="${dtDa}" cssClass="date" cssErrorClass="input-error date"/>
						<form:errors path="dataDa" cssClass="error" style="margin-left:40px"></form:errors>
					</p>
					
					<p class="forms-inline">
						<fmt:formatDate value="${dataA}" pattern="dd/MM/yyyy" var="dtA"/>
						<form:label path="dataDa" cssErrorClass="error">A quando? (GG/MM/AAAA) <em class="req">*</em></form:label>
						<form:input  path="dataA" value="${dtA}" cssClass="date" cssErrorClass="input-error date"/>
						<form:errors path="dataA" cssClass="error" style="margin-left:40px"></form:errors>
					</p>
					
					<p class="forms-inline">
						<form:hidden id="pagina" path="pagina"/>
						<form:hidden path="recordPerPagina" />
						<input type="hidden" name="_eventId" id="eventId" value="refreshOpportunita"> 
						<input type="reset" class="btn" value="Annulla"> 
						<input type="button" id="cercaTraLeOpportunita" class="btn btn-round" onclick="resetAndSubmitForm()" value="Cerca tra le opportunita" />
					</p>
				</fieldset>				
				
				<c:set var="opportunitaList" value="${ricercaOpportunitaForm.opportunita}" scope="session" />
				<c:if test="${not empty opportunitaList}">
	 				<c:out value="${pagedOpportunitaBanner}" escapeXml="false"></c:out> 
					
					<table style="margin:auto;width:750px">
					<tr>
						<td>
							<table style="margin:auto;">
								<tr>
									<td style="width:125px;border:0">
										Nome
									</td>	
									<td style="width:125px;border:0">
										Progressivo
									</td>
									<td style="width:125px;border:0">
										Codice
									</td>
									<td style="width:125px;border:0">
										Azienda
									</td>
									<td style="width:30px;border:0">
										&nbsp;
									</td>									
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td colSpan="6" style="width:750px;padding-left:0px;padding-right:0px;">
							<div style="width:100%;overflow-y:scroll;height:200px;">
								<table style="text-align:left;">
									<c:forEach var="recordOpportunita" items="${opportunitaList}" varStatus="opportunita" begin="0" >
										<tr>
											<td style="width:125px;text-align:center;padding-left:20px;padding-right:0px;">
												<c:out value="${recordOpportunita.Descrizione}"></c:out>
											</td>
											<td style="width:125px;text-align:center;padding-left:20px;padding-right:0px;">
												<c:out value="${recordOpportunita.progressivo}"></c:out>
											</td>
											<td style="width:125px;text-align:center;padding-left:20px;padding-right:0px;">
												<c:out value="${recordOpportunita.codice}"></c:out>
											</td>	
											<td style="width:125px;text-align:center;padding-left:20px;padding-right:0px;">
												<c:out value="${recordOpportunita.azienda.nome}"></c:out>
											</td>	
											<td style="width:30px;text-align:center;">
												<a href="${flowExecutionUrl}&_eventId=dettaglioOpportunita&idOpportunita=${recordOpportunita.idOpportunita}&idAzienda=${recordOpportunita.azienda.idAzienda}">
													<img alt="Visualizza opportunita" src="${edit}" border="0">
												</a>	
											</td>				
										</tr>
									</c:forEach>	
								</table>
							</div>
						</td>
					</tr>
				</table>
			</c:if>
			<c:if test="${ricercaOpportunitaForm.searched == true}">
				<c:if test="${empty opportunitaList}">
					<div align="center">
						<strong>Non sono presenti opportunit&agrave; con il filtro impostato.</strong>
					</div>
				</c:if>
			</c:if>
		</form:form>
	</div>
</div>